package com.tour.service.impl;

import com.tour.config.ResponseWrapper;
import com.tour.entity.Picture;
import com.tour.mapper.PictureMapper;
import com.tour.service.PictureService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lel
 * @since 2021-04-26
 */
@Service
public class PictureServiceImpl extends ServiceImpl<PictureMapper, Picture> implements PictureService {

    @Autowired
    PictureMapper pictureMapper;

    public ResponseWrapper addPic(Picture picture){
        if (picture == null){
            return ResponseWrapper.markError();
        }else {
            int result = pictureMapper.insert(picture);
            if (result == 1){
                return ResponseWrapper.markSuccess(null);
            }else {
                return ResponseWrapper.markError();
            }
        }
    }

    public ResponseWrapper deletePic(Integer pid){
        if (pid == null){
            return ResponseWrapper.markError();
        }else {
            int result = pictureMapper.deleteById(pid);
            if (result == 1){
                return ResponseWrapper.markSuccess(null);
            }else {
                return ResponseWrapper.markError();
            }
        }
    }
    public ResponseWrapper updatePic(Picture picture){
        if (picture == null){
            return ResponseWrapper.markError();
        }else {
            int result = pictureMapper.updateById(picture);
            if (result == 1){
                return ResponseWrapper.markSuccess(null);
            }else {
                return ResponseWrapper.markError();
            }
        }
    }

    public ResponseWrapper findaAllPic(){
        List<Picture> pictureList = pictureMapper.selectList(null);
        ResponseWrapper wrapper = ResponseWrapper.markSuccess(pictureList);
        wrapper.getData().put("date",pictureList);
        return wrapper;
    }

}
